package org.jianfa.homework.spring.controller;

import org.apache.dubbo.config.annotation.Reference;
import org.jianfa.learn.dubbo.api.HelloService;
import org.jianfa.learn.dubbo.filter.RequestContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class HelloController {

    @Reference
    private HelloService helloService;

    @GetMapping("/sayHello")
    public String sayHello(HttpServletRequest httpServletRequest,
                           @RequestParam("name") String name) {
        RequestContext.REQUEST_LOCAL.set(httpServletRequest);
        String result = helloService.sayHello(name);
        return result;
    }

}
